package work20241221;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * @author zdl
 * @date 2024/12/21
 */
class MyCallable implements Callable<String>{

    @Override
    public String call() throws Exception {
        for (int i = 0; i < 1000; i++) {
            System.out.println("中午吃饺子"+i);
        }
        return "执行完毕";
    }
}
public class Demo5 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable myCallable = new MyCallable();
        FutureTask<String> stringFutureTask = new FutureTask<>(myCallable);
        new Thread(stringFutureTask).start();
        //new Thread(new FutureTask<String >(new MyCallable())).start();
        String s = stringFutureTask.get();
        System.out.println(s);
    }
}
